﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Character;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x02000415 RID: 1045
public class CheckColorCustomMaterial : MonoBehaviour
{
	// Token: 0x060019FE RID: 6654 RVA: 0x000A680C File Offset: 0x000A4A0C
	private void Start()
	{
	}

	// Token: 0x060019FF RID: 6655 RVA: 0x000A6810 File Offset: 0x000A4A10
	private void Update()
	{
		float value = (float)this.now / (float)this.dataNum;
		this.slider.value = value;
	}

	// Token: 0x06001A00 RID: 6656 RVA: 0x000A683C File Offset: 0x000A4A3C
	public void Exe()
	{
		this.now = 0;
		base.StartCoroutine(this.Calc_Accessory());
	}

	// Token: 0x06001A01 RID: 6657 RVA: 0x000A6854 File Offset: 0x000A4A54
	private IEnumerator Calc_Wear()
	{
		this.dataNum = 0;
		for (WEAR_TYPE wear_TYPE = WEAR_TYPE.TOP; wear_TYPE < WEAR_TYPE.NUM; wear_TYPE++)
		{
			this.dataNum += CustomDataManager.GetWearDictionary_Female(wear_TYPE).Count;
		}
		for (WEAR_TYPE i = WEAR_TYPE.TOP; i < WEAR_TYPE.NUM; i++)
		{
			Dictionary<int, WearData> wear_datas = CustomDataManager.GetWearDictionary_Female(i);
			foreach (KeyValuePair<int, WearData> item in wear_datas)
			{
				this.now++;
				this.Calc_WearData(item.Value);
				yield return null;
			}
		}
		GlobalData.Debug_Log("完了");
		yield break;
	}

	// Token: 0x06001A02 RID: 6658 RVA: 0x000A6870 File Offset: 0x000A4A70
	private void Calc_WearData(WearData data)
	{
		if (data == null)
		{
			return;
		}
		GameObject gameObject = AssetBundleLoader.LoadAndInstantiate<GameObject>(data.assetbundleDir, data.assetbundleName, data.prefab);
		if (gameObject == null)
		{
			GlobalData.Debug_Log("可以读:" + data.name);
			return;
		}
		Dictionary<string, int> dictionary = new Dictionary<string, int>();
		this.CheckObj(dictionary, gameObject);
		UnityEngine.Object.Destroy(gameObject);
		if (dictionary.Count > 0)
		{
			this.datas.Add(new CheckColorCustomMaterial.Data(data, dictionary));
		}
	}

	// Token: 0x06001A03 RID: 6659 RVA: 0x000A68F0 File Offset: 0x000A4AF0
	private IEnumerator Calc_Accessory()
	{
		this.dataNum = 0;
		for (ACCESSORY_TYPE accessory_TYPE = ACCESSORY_TYPE.HEAD; accessory_TYPE < ACCESSORY_TYPE.NUM; accessory_TYPE++)
		{
			this.dataNum += CustomDataManager.GetAccessoryDictionary(accessory_TYPE).Count;
		}
		for (ACCESSORY_TYPE i = ACCESSORY_TYPE.HEAD; i < ACCESSORY_TYPE.NUM; i++)
		{
			Dictionary<int, AccessoryData> acce_datas = CustomDataManager.GetAccessoryDictionary(i);
			foreach (KeyValuePair<int, AccessoryData> item in acce_datas)
			{
				this.now++;
				this.Calc_AccessoryData(item.Value);
				yield return null;
			}
		}
		GlobalData.Debug_Log("完了");
		yield break;
	}

	// Token: 0x06001A04 RID: 6660 RVA: 0x000A690C File Offset: 0x000A4B0C
	private void Calc_AccessoryData(AccessoryData data)
	{
		if (data == null)
		{
			return;
		}
		GameObject gameObject = AssetBundleLoader.LoadAndInstantiate<GameObject>(data.assetbundleDir, data.assetbundleName, data.prefab_F);
		GameObject gameObject2 = AssetBundleLoader.LoadAndInstantiate<GameObject>(data.assetbundleDir, data.assetbundleName, data.prefab_M);
		if (gameObject == null && gameObject2 == null)
		{
			GlobalData.Debug_Log("可以读:" + data.name);
			return;
		}
		Dictionary<string, int> dictionary = new Dictionary<string, int>();
		this.CheckObj(dictionary, gameObject);
		this.CheckObj(dictionary, gameObject2);
		if (gameObject != null)
		{
			UnityEngine.Object.Destroy(gameObject);
		}
		if (gameObject2 != null)
		{
			UnityEngine.Object.Destroy(gameObject2);
		}
		if (dictionary.Count > 0)
		{
			this.datas.Add(new CheckColorCustomMaterial.Data(data, dictionary));
		}
	}

	// Token: 0x06001A05 RID: 6661 RVA: 0x000A69D8 File Offset: 0x000A4BD8
	private void CheckObj(Dictionary<string, int> dic, GameObject obj)
	{
		if (obj == null)
		{
			return;
		}
		Renderer[] componentsInChildren = obj.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer renderer in componentsInChildren)
		{
			if (renderer.CompareTag("ObjColor"))
			{
				foreach (Material material in renderer.sharedMaterials)
				{
					if (dic.ContainsKey(material.name))
					{
						string name;
						dic[name = material.name] = dic[name] + 1;
					}
					else
					{
						dic.Add(material.name, 1);
					}
				}
			}
		}
	}

	// Token: 0x06001A06 RID: 6662 RVA: 0x000A6A90 File Offset: 0x000A4C90
	public void Save(StreamWriter writer)
	{
		foreach (CheckColorCustomMaterial.Data data in this.datas)
		{
			data.Save(writer);
		}
	}

	// Token: 0x04001CE4 RID: 7396
	private List<CheckColorCustomMaterial.Data> datas = new List<CheckColorCustomMaterial.Data>();

	// Token: 0x04001CE5 RID: 7397
	private int now;

	// Token: 0x04001CE6 RID: 7398
	private int dataNum;

	// Token: 0x04001CE7 RID: 7399
	[SerializeField]
	private Slider slider;

	// Token: 0x02000416 RID: 1046
	private class Data
	{
		// Token: 0x06001A07 RID: 6663 RVA: 0x000A6AEC File Offset: 0x000A4CEC
		public Data(WearData wearData, Dictionary<string, int> dic)
		{
			this.name = wearData.name;
			this.prefab = wearData.prefab;
			foreach (string item in dic.Keys)
			{
				this.materialNames.Add(item);
			}
		}

		// Token: 0x06001A08 RID: 6664 RVA: 0x000A6B78 File Offset: 0x000A4D78
		public Data(AccessoryData acceData, Dictionary<string, int> dic)
		{
			this.name = acceData.name;
			this.prefab = acceData.prefab_F;
			foreach (string item in dic.Keys)
			{
				this.materialNames.Add(item);
			}
		}

		// Token: 0x06001A09 RID: 6665 RVA: 0x000A6C04 File Offset: 0x000A4E04
		public void Save(StreamWriter writer)
		{
			writer.Write(this.name);
			writer.Write("\t");
			writer.Write(this.materialNames.Count);
			foreach (string value in this.materialNames)
			{
				writer.Write("\t");
				writer.Write(value);
			}
			writer.WriteLine();
		}

		// Token: 0x04001CE8 RID: 7400
		public string name;

		// Token: 0x04001CE9 RID: 7401
		public string prefab;

		// Token: 0x04001CEA RID: 7402
		private List<string> materialNames = new List<string>();
	}
}
